#!/bin/bash

# 容器名称
CONTAINER_NAME="DemoFlake"

# 本地路径和容器内路径
LOCAL_PATH="/Users/jackiezheng/liushi/FindFakePlateVehicle-web"
CONTAINER_PATH="/opt/project"

# 检查容器是否已经存在
if [[ $(docker ps -a --filter "name=${CONTAINER_NAME}" --format '{{.Names}}') == "$CONTAINER_NAME" ]]; then
  echo "Starting existing Docker container ${CONTAINER_NAME}..."
  docker start $CONTAINER_NAME
else
  echo "Creating and starting new Docker container ${CONTAINER_NAME}..."
  docker run -d --name $CONTAINER_NAME -p 8090:8090 -p 5000:5000 \
    -v $LOCAL_PATH:$CONTAINER_PATH \
    fakeplate-python3:latest /bin/bash -c "sleep infinity"
fi

# 等待 5 秒
echo "Waiting for 5 seconds for the container to initialize..."
sleep 5


echo "Starting Flask services using start_server.py..."
docker exec $CONTAINER_NAME /bin/bash -c "cd /opt/project && python3 start_server.py" &

echo "Waiting for 20 seconds for the first flask..."
sleep 20


# 在容器内通过 python3 启动 Flask 服务
echo "Starting Flask services using start_server.py..."
docker exec $CONTAINER_NAME /bin/bash -c "cd /app/DarkNetAPI && python3 start_server.py" &

echo "Flask services started."
